#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/1/16 0016 10:42
# @Author  : Arliki
# @email   : hkdnxycz@outlook.com
# @File    : lib_request
import requests
import re


def run_get():
    # r=requests.get('http://www.baidu.com')
    # print(r.status_code)
    # print(r.text)
    # 带参数提交返回   r.encoding返回获取内容的编码
    # r = requests.get('https://www.douban.com/search', params={'q': 'python', 'cat': '1001'})
    # print(r.url)
    # print(r.encoding)
    # json直接获取json格式         r.content返回bytes格式/二进制
    r = requests.get(
        'http://m.kuaidi100.com/query?type=yunda&postid=3902757987412&id=1&valicode=&temp=0.906445064981234')
    data = r.json()
    print(data['message'])
    print(r.headers)
    # 需要传入header
    # r = requests.get('https://www.douban.com/',headers={'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit'})
    # print(r.text)


def run_post():
    # post数据放在data里
    # r = requests.post('https://accounts.douban.com/login',data={'form_email': 'abc@example.com', 'form_password': '123456'})
    # json格式传入数据
    params = {'form_email': 'abc@example.com', 'form_password': '123456'}
    # cookies
    cs = {'token': '123'}
    # headers
    hd = {'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit'}
    # 超时直接传入timeout=?/s
    r = requests.post('https://accounts.douban.com/login', json=params, cookies=cs, headers=hd)
    # f=open('ttt.html','w+',encoding='utf-8')
    # f.write(r.text)
    # f.close()
    # print(r.text)
    print(r.headers)


if __name__ == '__main__':
    run_get()
    run_post()
